import request from '@/utils/request'

export function add(data) {
  return request({
    url: 'api/memberCards',
    method: 'post',
    data
  })
}

export function del(ids) {
  return request({
    url: 'api/memberCards/',
    method: 'delete',
    data: ids
  })
}

export function edit(data) {
  return request({
    url: 'api/memberCards',
    method: 'put',
    data
  })
}

// 新增生成卡号的请求
export function generateCardNumber() {
  return request({
    url: '/api/generateSerialNumber?type=card',
    method: 'get'
  })
}

// 获取会员的所有卡
export function getMemberCards(memberId) {
  return request({
    url: `api/memberCards/member/${memberId}`,
    method: 'get'
  })
}

// 会员卡充值
export function rechargeCard(data) {
  return request({
    url: 'api/memberCards/recharge',
    method: 'post',
    data
  })
}

// 获取充值记录
export function getRechargeRecords(cardId) {
  return request({
    url: `api/rechargeRecords/recharge/${cardId}`,
    method: 'get'
  })
}

// 撤销充值记录
export function revokeRecharge(recordId) {
  return request({
    url: `api/rechargeRecords/revoke/${recordId}`,
    method: 'post'
  })
}

// 添加退卡方法
export function refundCard(data) {
  return request({
    url: 'api/memberCards/refund',
    method: 'post',
    data
  })
}

export default { add, edit, del, generateCardNumber, getMemberCards, rechargeCard, revokeRecharge }
